<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-body">
                <div class="row pd-10">
                    <div class="col-md-3 pd-5">
                        <div class="input-group">
                            <span class="input-group-addon">姓名</span>
                            <input type="text" class="form-control" id="name" value="" placeholder=""/>
                        </div>
                    </div>
                    <div class="col-md-3 pd-5">
                        <div class="input-group">
                            <span class="input-group-addon">年龄</span>
                            <input type="text" class="form-control double" id="ageBegin" value="" placeholder="起始值"/>
                            <span class="form-control split">-</span>
                            <input type="text" class="form-control double" id="ageEnd" value="" placeholder="结束值"/>
                        </div>
                    </div>
                    <div class="col-md-3 pd-5">
                        <div class="input-group">
                            <span class="input-group-addon">年龄</span>
                            <input type="text" class="form-control" id="age" value="" placeholder=""/>
                        </div>
                    </div>
                    <div class="col-md-3 pd-5">
                        <div class="input-group">
                            <span class="input-group-addon">生日</span>
                            <input type="text" class="form-control double" id="birthBegin" value=""
                                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" placeholder="起始值"/>
                            <span class="form-control split">-</span>
                            <input type="text" class="form-control double" id="birthEnd" value=""
                                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" placeholder="结束值"/>
                        </div>
                    </div>
                    <div class="col-md-3 pd-5">
                        <div class="input-group">
                            <span class="input-group-addon">生日</span>
                            <input type="text" class="form-control" id="birth" value="" placeholder=""/>
                        </div>
                    </div>
                    <div class="col-md-3 pd-5">
                        <div class="input-group">
                            <span class="input-group-addon">创建时间</span>
                            <input type="text" class="form-control double" id="createTimeBegin" value=""
                                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" placeholder="起始值"/>
                            <span class="form-control split">-</span>
                            <input type="text" class="form-control double" id="createTimeEnd" value=""
                                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" placeholder="结束值"/>
                        </div>
                    </div>
                    <div class="col-md-3 pd-5">
                        <div class="input-group">
                            <span class="input-group-addon">创建时间</span>
                            <input type="text" class="form-control" id="createTime" value="" placeholder=""/>
                        </div>
                    </div>
                </div>
                <div class="fixed-table-toolbar">
                    <div class="columns pull-left">
                        <button type="button" class="btn  btn-primary" onclick="add()">
                            <i class="fa fa-plus" aria-hidden="true"></i>添加
                        </button>
                        <button type="button" class="btn  btn-danger"
                                onclick="batchRemove()">
                            <i class="fa fa-trash" aria-hidden="true"></i>删除
                        </button>
                    </div>
                    <div class="columns pull-right">
                        <button class="btn btn-success" onclick="reLoad()">查询</button>
                    </div>
                    <div class="columns pull-right col-md-2 nopadding">
                        <input id="searchName" type="text" class="form-control"
                               placeholder="输入搜索关键字"/>
                    </div>
                </div>
                <table id="exampleTable" data-mobile-responsive="true">
                </table>
            </div>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:utext="'var defaultImg = \''+${defaultImg}+'\';'"></script>
<script type="text/javascript">
    var prefix = "/system/student";
    $(function () {
        load();
        $('#searchName').keydown(function (evt) {
            if (evt.keyCode == 13) reLoad();
        });
    });

    function load() {
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get', // 服务器数据的请求方式 get or post
                    url: prefix + "/list", // 服务器数据的加载地址
                    //	showRefresh : true,
                    //	showToggle : true,
                    //	showColumns : true,
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: true, // 设置为true会有隔行变色效果
                    dataType: "json", // 服务器返回的数据类型
                    pagination: true, // 设置为true会在底部显示分页条
                    // queryParamsType : "limit",
                    // //设置为limit则会发送符合RESTFull格式的参数
                    singleSelect: false, // 设置为true将禁止多选
                    // contentType : "application/x-www-form-urlencoded",
                    // //发送到服务器的数据编码类型
                    pageSize: 10, // 如果设置了分页，每页数据条数
                    pageNumber: 1, // 如果设置了分布，首页页码
                    //search : true, // 是否显示搜索框
                    showColumns: false, // 是否显示内容下拉框（选择显示的列）
                    sidePagination: "server", // 设置在哪里进行分页，可选值为"client" 或者 "server"
                    queryParams: function (params) {
                        return {
                            //说明：传入后台的参数包括offset开始索引，limit步长，sort排序列，order：desc或者,以及所有列的键值对
                            limit: params.limit,
                            offset: params.offset,
                            search: $('#searchName').val(),
                            name: $('#name').val(),
                            ageBegin: $('#ageBegin').val(),
                            ageEnd: $('#ageEnd').val(),
                            age: $('#age').val(),
                            birthBegin: $('#birthBegin').val(),
                            birthEnd: $('#birthEnd').val(),
                            birth: $('#birth').val(),
                            createTimeBegin: $('#createTimeBegin').val(),
                            createTimeEnd: $('#createTimeEnd').val(),
                            createTime: $('#createTime').val(),
                        };
                    },
                    // //请求服务器数据时，你可以通过重写参数的方式添加一些额外的参数，例如 toolbar 中的参数 如果
                    // queryParamsType = 'limit' ,返回参数必须包含
                    // limit, offset, search, sort, order 否则, 需要包含:
                    // pageSize, pageNumber, searchText, sortName,
                    // sortOrder.
                    // 返回false将会终止请求
                    columns: [
                        {
                            checkbox: true
                        },
                        {
                            field: 'id',
                            title: ''
                        },
                        {
                            field: 'name',
                            title: '姓名'
                        },
                        {
                            field: 'headUrl',
                            title: '头像',
                            formatter: function(value) {
                                if(value == '##IMG##') {
                                    value = defaultImg;
                                }
                                return '<img src="'+value+'" class="table-img" /';
                            }
                        },
                        {
                            field: 'age',
                            title: '年龄'
                        },
                        {
                            field: 'birth',
                            title: '生日',
                            formatter: function (value) {
                                return value;
                            }
                        },
                        {
                            field: 'createTime',
                            title: '创建时间',
                            formatter: function (value) {
                                return value;
                            }
                        },
                        {
                            title: '操作',
                            field: 'id',
                            align: 'center',
                            formatter: function (value, row, index) {
                                var e = '<a class="btn btn-primary btn-sm" href="#" mce_href="#" title="编辑" onclick="edit(\''
                                    + row.id
                                    + '\')">编辑</a> ';
                                var d = '<a class="btn btn-danger btn-sm" href="#" title="删除"  mce_href="#" onclick="remove(\''
                                    + row.id
                                    + '\')">删除</a> ';
                                var f = '<a class="btn btn-warning btn-sm" href="#" title="查看"  mce_href="#" onclick="unique(\''
                                    + row.id
                                    + '\')">查看</a> ';
                                return [showButton(f, true), showButton(e, true), showButton(d, true)].join('');
                            }
                        }]
                });
    }

    function showButton(c, b) {
        return b ? c : '';
    }

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }

    function add() {
        var index = layer.open({
            type: 2,
            title: '增加',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['800px', '520px'],
            content: prefix + '/add' // iframe的url
        });
        layer.full(index);
    }

    function unique(id) {
        var index = layer.open({
            type: 2,
            title: '查看',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['800px', '520px'],
            content: prefix + '/unique/' + id // iframe的url
        });
        layer.full(index);
    }

    function edit(id) {
        var index = layer.open({
            type: 2,
            title: '编辑',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['800px', '520px'],
            content: prefix + '/edit/' + id // iframe的url
        });
        layer.full(index);
    }

    function remove(id) {
        layer.confirm('确定要删除选中的记录？', {
            btn: ['确定', '取消']
        }, function () {
            $.ajax({
                url: prefix + "/remove",
                type: "post",
                data: {
                    'id': id
                },
                success: function (r) {
                    if (r.code == 0) {
                        layer.msg(r.msg);
                        reLoad();
                    } else {
                        layer.msg(r.msg);
                    }
                }
            });
        })
    }

    function batchRemove() {
        var rows = $('#exampleTable').bootstrapTable('getSelections'); // 返回所有选择的行，当没有选择的记录时，返回一个空数组
        if (rows.length == 0) {
            layer.msg("请选择要删除的数据");
            return;
        }
        layer.confirm("确认要删除选中的'" + rows.length + "'条数据吗?", {
            btn: ['确定', '取消']
            // 按钮
        }, function () {
            var ids = new Array();
            // 遍历所有选择的行数据，取每条数据对应的ID
            $.each(rows, function (i, row) {
                ids[i] = row['id'];
            });
            $.ajax({
                type: 'POST',
                data: {
                    "ids": ids
                },
                url: prefix + '/batchRemove',
                success: function (r) {
                    if (r.code == 0) {
                        layer.msg(r.msg);
                        reLoad();
                    } else {
                        layer.msg(r.msg);
                    }
                }
            });
        }, function () {

        });
    }
</script>
</body>
</html>